package com.itheima.reggie.controller;


import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CartController {
    @Autowired
    private CartService cartService;

    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo cartAdd(@RequestBody Cart cartParam) {

        Cart add = cartService.add(cartParam);

        return ResultInfo.success(add);
    }
    //查看购物车
    @GetMapping("/cart/list")
    public ResultInfo list(){
              List<Cart> list=cartService.list();
        return ResultInfo.success(list);
    }
    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo clear(){

        cartService.clear();
        return  ResultInfo.success();
    }
    //减少购物车
    @PostMapping("/cart/sub")
    public ResultInfo reduce(@RequestBody Cart cartParam){

         Cart cart=cartService.reduce(cartParam);


        return ResultInfo.success(cart);
    }
}
